﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;

namespace _4DJackPot
{
    public partial class FileLog
    {
        public FileLog()
        {

        }

        // Error Log
        public void WriteErrorLog(string errorMsgString)
        {
            try
            {
                if (Global.currLocalTime.wYear == 0)
                {
                    Global.SetCurrTime();
                }
                // Error Data Backup
                string errorDataBackupDirectoryString =
                    System.Windows.Forms.Application.StartupPath +
                    "\\Data\\Log\\" +
                    Global.currLocalTime.wYear.ToString() + "-" + Global.currLocalTime.wMonth.ToString("00") + "-" + Global.currLocalTime.wDay.ToString("00") + "\\";
                string errorDataBackupFileString =
                    Global.currLocalTime.wHour.ToString("00") + Global.currLocalTime.wMinute.ToString("00") + Global.currLocalTime.wSecond.ToString("00");
                System.IO.DirectoryInfo errorDataBackupDirectoryInfo = new System.IO.DirectoryInfo(errorDataBackupDirectoryString);
                if (errorDataBackupDirectoryInfo.Exists == false) errorDataBackupDirectoryInfo.Create();

                // Error Data Backup File Stream
                FileStream errorDataBackupFileStream = new FileStream(
                    errorDataBackupDirectoryString + errorDataBackupFileString + ".csv",
                    System.IO.FileMode.Append, System.IO.FileAccess.Write);
                StreamWriter errorDataBackupStreamWriter = new StreamWriter(errorDataBackupFileStream, System.Text.Encoding.Unicode);

                errorDataBackupStreamWriter.Write(errorMsgString);

                errorDataBackupStreamWriter.Close();
                errorDataBackupFileStream.Close();
            }
            catch (Exception)
            {

            }
        }
    }
}
